public class Solution7 {
    public int reverse(int x) {
        int n = 0;
        while (x != 0) {
            int t = n * 10;
            if (t / 10 != n) {
                return 0;
            }
            n *= 10;
            n += x % 10;
            x /= 10;
        }
        return n;
    }
}
